﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MyBusiness;

/// <summary>
/// More 的摘要说明。
/// </summary>
public partial class ManageInside_More : Page
{
    WebInfoOperation wifOperation = new WebInfoOperation();

    protected void Page_Load(object sender, System.EventArgs e)
    {
        if (!this.Page.IsPostBack)
        {
            string action = Request["action"];
            BindDG();

            if (action == "del")
            {
                string id = Request["id"];
                DataDelete(id);
            }
        }
    }

    /// <summary>
    /// 绑定
    /// </summary>
    private void BindDG()
    {
        DataTable ds = wifOperation.GetPubInfoByType("st_other", "", "order by fbsj desc");

        if (ds.Rows.Count>0)
        {
            this.DataGrid2.DataSource = ds;
            this.DataGrid2.DataBind();
        }
    }

    /// <summary>
    /// 分页
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void DataGrid2_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        if (this.DataGrid2.Items.Count == 1 && this.DataGrid2.CurrentPageIndex > 0)
        {
            this.DataGrid2.CurrentPageIndex--;
        }
        this.DataGrid2.CurrentPageIndex = e.NewPageIndex;
        BindDG();
    }

    /// <summary>
    /// 行命令
    /// </summary>
    /// <param name="source"></param>
    /// <param name="e"></param>
    protected void DataGrid2_ItemCommand(object source, DataGridCommandEventArgs e)
    {
        if (e.Item.ItemIndex != -1 && e.Item.ItemIndex >= 0)
        {
            if (e.CommandName == "Delete")
            {
                string id = DataGrid2.Items[e.Item.ItemIndex].Cells[0].Text;
                DataDelete(id);
            }
        }
    }

    /// <summary>
    /// 删除数据
    /// </summary>
    /// <param name="id"></param>
    protected void DataDelete(string id)
    {
        if (!string.IsNullOrEmpty(id))
        {
            wifOperation.DeleteArticle(id);

            BindDG();
        }
        else
        {
            Response.Write("<script>alert('删除失败');</script>");
        }
    }

    /// <summary>
    /// 行绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DataGrid2_ItemDataBound(object sender, DataGridItemEventArgs e)
    {
        if (e.Item.ItemIndex != -1 && e.Item.ItemIndex >= 0)
        {
            string strUrl = string.Empty;

            string s = e.Item.ToString();
            DataRowView dRowView = e.Item.DataItem as DataRowView;
            String id = dRowView["ID"].ToString();
            String type = dRowView["type"].ToString();

            HyperLink hylkDel = e.Item.FindControl("hldel") as HyperLink;
            hylkDel.NavigateUrl = "More.aspx?id=" + id + "&action=del&type=" + type;
            hylkDel.Visible = true;
            HyperLink hylkmodify = e.Item.FindControl("hlmodify") as HyperLink;

            hylkmodify.NavigateUrl = "webpubmanager.aspx?id=" + id + "&action=modify&type=" + type;
            hylkmodify.Visible = true;
        }
    }
}